﻿using System.Collections.Generic;
using System.Linq;
using Loki.Bot;
using Loki.Game.GameData;
using Loki.Game.Objects;

namespace toNyxIncinerate
{
    public class Target
    {
        /// <summary>
        ///     Returns the best focusable object on the TargetList. (optimized for Facebreaker builds ! be careful !)
        /// </summary>
        public static Monster BestTarget
        {
            get
            {
                /*
                // Special totem focus
                if (SpecialTotemsCount > 0)
                    return
                        TargetList.First(tar => SpecialTotemsFocus.Contains(tar.Name));

                // Unique mobs focus
                if (SpecialMobCount(Rarity.Unique) > 0)
                    return
                        TargetList.First(tar => tar.Rarity == Rarity.Unique);

                // Rare mobs focus
                if (SpecialMobCount(Rarity.Rare) > 0)
                    return
                        TargetList.First(tar => tar.Rarity == Rarity.Rare);

                // Must Focus Targets
                if (MustFocusUnitsCount > 0)
                    return
                        TargetList.First(tar => MustFocusUnits.Contains(tar.Name));
                */
                // Normal target
                return (Monster)Targeting.Combat.Targets.OrderBy(t => t.Distance).FirstOrDefault();
            }
        }

        public static IEnumerable<Monster> TargetList
        {
            get { return Targeting.Combat.Targets.OfType<Monster>(); }
        }

        public static int SpecialMobCount(Rarity myRarity)
        {
            return TargetList.Count(tar => tar.Rarity == myRarity);
        }

        public static int SpecialTotemsCount
        {
            get { return TargetList.Count(tar => SpecialTotemsFocus.Contains(tar.Name)); }
        }

        public static int MustFocusUnitsCount
        {
            get { return TargetList.Count(tar => MustFocusUnits.Contains(tar.Name)); }
        }

        private static readonly List<string> MustFocusUnits = new List<string>
        {
               "Ancient Construct", // Poisonous shit in Ancient Pyramid
               "Necromancer", // Necromancers in A1's Prison
               "Defiler", // Defilers in A2
        };

        // List of the totems we need to focus, that can be pain in the ass and could slow down bot
        private static readonly List<string> SpecialTotemsFocus = new List<string>
        {
            "Detonating Totem"                                                         ,
            "Necromantic Totem",
            "Vaal Totem"
        };

    }
}
